<template>
  <el-dialog :title="!dataForm.id ? '新增' : '修改'" :close-on-click-modal="false" :visible.sync="visible" center>
    <el-button class="miui-dialog-close-btn" @click="visible = false">关闭页面</el-button>
    <el-form class="verify-form" :model="dataForm" :rules="dataRule" ref="dataForm" label-width="80px">
      <el-form-item label="单号" prop="takeBillId">
        <el-input v-model="dataForm.takeBillId" placeholder="单号"></el-input>
      </el-form-item>
      <el-form-item label="入库仓库id" prop="inStockId">
        <el-input v-model="dataForm.inStockId" placeholder="入库仓库id"></el-input>
      </el-form-item>
      <el-form-item label="出库仓库id" prop="outStockId">
        <el-input v-model="dataForm.outStockId" placeholder="出库仓库id"></el-input>
      </el-form-item>
      <el-form-item label="制造商id" prop="supplyId">
        <el-input v-model="dataForm.supplyId" placeholder="制造商id"></el-input>
      </el-form-item>
      <el-form-item label="部门id" prop="deptId">
        <el-input v-model="dataForm.deptId" placeholder="部门id"></el-input>
      </el-form-item>
      <el-form-item label="领用(部门/客户)id" prop="receptionId">
        <el-input v-model="dataForm.receptionId" placeholder="领用(部门/客户)id"></el-input>
      </el-form-item>
      <el-form-item label="领用名称" prop="receptionName">
        <el-input v-model="dataForm.receptionName" placeholder="领用名称"></el-input>
      </el-form-item>
      <el-form-item label="领用类型(1-部门领用,2-客户领用)" prop="receptionType">
        <el-input v-model="dataForm.receptionType" placeholder="领用类型(1-部门领用,2-客户领用)"></el-input>
      </el-form-item>
      <el-form-item label="商品品种id" prop="brandId">
        <el-input v-model="dataForm.brandId" placeholder="商品品种id"></el-input>
      </el-form-item>
      <el-form-item label="商品类别id" prop="ctgId">
        <el-input v-model="dataForm.ctgId" placeholder="商品类别id"></el-input>
      </el-form-item>
      <el-form-item label="库存订单备注" prop="memo">
        <el-input v-model="dataForm.memo" placeholder="库存订单备注"></el-input>
      </el-form-item>
      <el-form-item label="库存状态字典id" prop="inveStatus">
        <el-input v-model="dataForm.inveStatus" placeholder="库存状态字典id"></el-input>
      </el-form-item>
      <el-form-item label="出库类型字典id(1-销售出库,2-领用出库,3-其他出库)" prop="inveType">
        <el-input v-model="dataForm.inveType" placeholder="出库类型字典id(1-销售出库,2-领用出库,3-其他出库)"></el-input>
      </el-form-item>
      <el-form-item label="是否审核(1-是,0-否)" prop="isAudit">
        <el-input v-model="dataForm.isAudit" placeholder="是否审核(1-是,0-否)"></el-input>
      </el-form-item>
      <el-form-item label="审核出库用户id" prop="auditUser">
        <el-input v-model="dataForm.auditUser" placeholder="审核出库用户id"></el-input>
      </el-form-item>
      <el-form-item label="审核出库时间" prop="auditTime">
        <el-input v-model="dataForm.auditTime" placeholder="审核出库时间"></el-input>
      </el-form-item>
      <el-form-item label="财务结算用户id" prop="financeUser">
        <el-input v-model="dataForm.financeUser" placeholder="财务结算用户id"></el-input>
      </el-form-item>
      <el-form-item label="财务结算时间" prop="financeTime">
        <el-input v-model="dataForm.financeTime" placeholder="财务结算时间"></el-input>
      </el-form-item>
      <el-form-item label="创建时间" prop="createTime">
        <el-input v-model="dataForm.createTime" placeholder="创建时间"></el-input>
      </el-form-item>
      <el-form-item label="修改时间" prop="updateTime">
        <el-input v-model="dataForm.updateTime" placeholder="修改时间"></el-input>
      </el-form-item>
      <el-form-item label="创建用户id" prop="createUser">
        <el-input v-model="dataForm.createUser" placeholder="创建用户id"></el-input>
      </el-form-item>
      <el-form-item label="修改用户id" prop="modifyUser">
        <el-input v-model="dataForm.modifyUser" placeholder="修改用户id"></el-input>
      </el-form-item>
      <el-form-item label="租户id" prop="tenantId">
        <el-input v-model="dataForm.tenantId" placeholder="租户id"></el-input>
      </el-form-item>
      <el-form-item label="组织id" prop="orgId">
        <el-input v-model="dataForm.orgId" placeholder="组织id"></el-input>
      </el-form-item>
      <el-form-item label="单位id" prop="unitId">
        <el-input v-model="dataForm.unitId" placeholder="单位id"></el-input>
      </el-form-item>
      <el-form-item label="逻辑删除(1-正常,-1已删除)" prop="delFlag">
        <el-input v-model="dataForm.delFlag" placeholder="逻辑删除(1-正常,-1已删除)"></el-input>
      </el-form-item>
    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button @click="visible = false">取消</el-button>
      <el-button type="primary" @click="dataFormSubmit" v-prevent-re-click>确定</el-button>
    </span>
  </el-dialog>
</template>

<script>
  import { getObj, editOutboundInfo } from '@/api/eims/take-inventory/eimstakeinventory'

  export default {
    data() {
      return {
        visible: false,
        dataForm: {
          id: 0,
          takeBillId: '',
          inStockId: '',
          outStockId: '',
          supplyId: '',
          deptId: '',
          receptionId: '',
          receptionName: '',
          receptionType: '',
          brandId: '',
          ctgId: '',
          memo: '',
          inveStatus: '',
          inveType: '',
          isAudit: '',
          auditUser: '',
          auditTime: '',
          financeUser: '',
          financeTime: '',
          createTime: '',
          updateTime: '',
          createUser: '',
          modifyUser: '',
          tenantId: '',
          orgId: '',
          unitId: '',
          delFlag: ''
        },
        dataRule: {
          takeBillId: [{
            required: true,
            message: '单号不能为空',
            trigger: 'blur'
          }],
          inStockId: [{
            required: true,
            message: '入库仓库id不能为空',
            trigger: 'blur'
          }],
          outStockId: [{
            required: true,
            message: '出库仓库id不能为空',
            trigger: 'blur'
          }],
          supplyId: [{
            required: true,
            message: '制造商id不能为空',
            trigger: 'blur'
          }],
          deptId: [{
            required: true,
            message: '部门id不能为空',
            trigger: 'blur'
          }],
          receptionId: [{
            required: true,
            message: '领用(部门/客户)id不能为空',
            trigger: 'blur'
          }],
          receptionName: [{
            required: true,
            message: '领用名称不能为空',
            trigger: 'blur'
          }],
          receptionType: [{
            required: true,
            message: '领用类型(1-部门领用,2-客户领用)不能为空',
            trigger: 'blur'
          }],
          brandId: [{
            required: true,
            message: '商品品种id不能为空',
            trigger: 'blur'
          }],
          ctgId: [{
            required: true,
            message: '商品类别id不能为空',
            trigger: 'blur'
          }],
          memo: [{
            required: true,
            message: '库存订单备注不能为空',
            trigger: 'blur'
          }],
          inveStatus: [{
            required: true,
            message: '库存状态字典id不能为空',
            trigger: 'blur'
          }],
          inveType: [{
            required: true,
            message: '出库类型字典id(1-销售出库,2-领用出库,3-其他出库)不能为空',
            trigger: 'blur'
          }],
          isAudit: [{
            required: true,
            message: '是否审核(1-是,0-否)不能为空',
            trigger: 'blur'
          }],
          auditUser: [{
            required: true,
            message: '审核出库用户id不能为空',
            trigger: 'blur'
          }],
          auditTime: [{
            required: true,
            message: '审核出库时间不能为空',
            trigger: 'blur'
          }],
          financeUser: [{
            required: true,
            message: '财务结算用户id不能为空',
            trigger: 'blur'
          }],
          financeTime: [{
            required: true,
            message: '财务结算时间不能为空',
            trigger: 'blur'
          }],
          createTime: [{
            required: true,
            message: '创建时间不能为空',
            trigger: 'blur'
          }],
          updateTime: [{
            required: true,
            message: '修改时间不能为空',
            trigger: 'blur'
          }],
          createUser: [{
            required: true,
            message: '创建用户id不能为空',
            trigger: 'blur'
          }],
          modifyUser: [{
            required: true,
            message: '修改用户id不能为空',
            trigger: 'blur'
          }],
          tenantId: [{
            required: true,
            message: '租户id不能为空',
            trigger: 'blur'
          }],
          orgId: [{
            required: true,
            message: '组织id不能为空',
            trigger: 'blur'
          }],
          unitId: [{
            required: true,
            message: '单位id不能为空',
            trigger: 'blur'
          }],
          delFlag: [{
            required: true,
            message: '逻辑删除(1-正常,-1已删除)不能为空',
            trigger: 'blur'
          }]
        }
      }
    },
    methods: {
      init(id) {
        this.dataForm.id = id || 0
        this.visible = true
        this.$nextTick(() => {
          this.$refs['dataForm'].resetFields()
          if (this.dataForm.id) {
            this.dataListLoading = true
            getObj(this.dataForm.id).then(response => {
              if(response.data.code == '0'){
                this.dataForm = response.data.data
              }else{
                this.$message.error(response.data.msg)
              }
              this.dataListLoading = false
            })
          }
        })
      },
      // 表单提交
      dataFormSubmit() {
        this.$refs['dataForm'].validate((valid) => {
          if (valid) {
            if (this.dataForm.id) {
              editOutboundInfo(this.dataForm).then(response => {
                if(response.data.code == '0'){
                  this.$message.success('修改成功')
                  this.visible = false
                  this.$emit('refreshDataList')
                }else{
                  this.$message.error(response.data.msg)
                }
              })
            }
          }
        })
      }
    }
  }
</script>
